Effect of moving window averaging on variance

This notebook shows that the variance of a random process which is the moving window integration of an uncorrelated Gaussian process scales with the number of points both for overlapping (correlated) and non-overlapping (uncorrelated) windows.

Mean of independent Gaussians

$$ X_i \sim \mathcal{N}\{0; \sigma^2\} \qquad i = 1..N$$$$ Y = \frac{1}{N}\,\sum_{i=1}^N X_i \;\sim\; \mathcal{N}\{0; \frac{\sigma^2}{N}\}$$

Covariance and Correlation

$$ X \sim \mathcal{N}\{0; \sigma_X^2\} \quad Y \sim \mathcal{N}\{0; \sigma_Y^2\} $$$$ \operatorname{cov}(X,Y) = \operatorname{E}[(X-\mu_X)(Y-\mu_Y)] $$$$ \rho_{X,Y}= \frac{\operatorname{cov}(X,Y)}{\sigma_X \sigma_Y} $$$$ Z = X + Y \;\sim\; \mathcal{N}\{0; \sigma_Z^2\} $$$$\sigma_Z^2 = \sigma_X^2 + \sigma_Y^2 + 2\operatorname{cov}(X,Y) = 2\,\sigma^2\,( 1 + \rho)$$

$\cdot$


In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

In [2]:
svar = []
for t_step in (1, 3, 5, 10, 20, 30):   
    t_window = 30
    decimation = 20
    nwindow = int(t_window / t_step * decimation)
    tot_steps = 100*1000
    tot_points = tot_steps * decimation

    s = np.random.randn(tot_points)
    x = np.array([s[i:i+nwindow].mean() for i in range(0, tot_points, decimation)])
    svar.append(x.var()*nwindow)
    
    ρ_emp = (x[::2]*x[1::2]).mean()*nwindow
    print('t_step = %2d;  ρ(exact) = %4.2f;  ρ(empiric) = %5.2f;  Var{X}⋅nwindow = %.2f' %
          (t_step, 1 - t_step/t_window, ρ_emp, x.var()*nwindow))


t_step =  1;  ρ(exact) = 0.97;  ρ(empiric) =  0.96;  Var{X}⋅nwindow = 0.99
t_step =  3;  ρ(exact) = 0.90;  ρ(empiric) =  0.90;  Var{X}⋅nwindow = 1.00
t_step =  5;  ρ(exact) = 0.83;  ρ(empiric) =  0.82;  Var{X}⋅nwindow = 0.99
t_step = 10;  ρ(exact) = 0.67;  ρ(empiric) =  0.67;  Var{X}⋅nwindow = 1.00
t_step = 20;  ρ(exact) = 0.33;  ρ(empiric) =  0.34;  Var{X}⋅nwindow = 1.01
t_step = 30;  ρ(exact) = 0.00;  ρ(empiric) = -0.01;  Var{X}⋅nwindow = 1.00

NOTE: x contains correlated samples. Its variance, however, scales linearly with the number of points in the averaging window n_avg, similarly to uncorrelated variables.


In [ ]: